<template>
<div style="text-align: center">
    <van-nav-bar fixed="true" title="添加案例" left-text="返回" left-arrow="" @click-left="onClickLeft">
    </van-nav-bar>

    <van-cell-group style="margin-top: 46px">
        <van-field
                readonly
                clickable
                name="picker"
                :value="kind"
                label="案例类别"
                placeholder="点击选择案例类别"
                @click="showPicker = true"
        />
        <van-popup v-model="showPicker" position="bottom">
            <van-picker
                    show-toolbar
                    :columns="columns"
                    @confirm="onConfirm"
                    @cancel="showPicker = false"
            />
        </van-popup>
        <van-field
                v-model="fileList"
                rows="1"
                autosize
                type="textarea"
                label="上传图片"
                placeholder="请添加在线图床图片url"
        />
        <van-field
                v-model="name"
                label="案例名"
                placeholder="请添加案例名"
        />
        <van-field
                v-model="title"
                label="简介"
                placeholder="请添加简介"
        />

        <van-field
                v-model="content"
                rows="2"
                autosize
                type="textarea"
                label="详细内容"
                placeholder="请添加详细内容"
        />

    </van-cell-group>
    <van-button @click="insertCase" style="margin-top: 10px" size="small" color="linear-gradient(to right, #4bb0ff, #6149f6)" round
                type="info">确认添加
    </van-button>
</div>
</template>

<script>
    export default {
        name: "caseAddManager",
        data(){
            return{
                showPicker: false,
                columns: ['行政案例', '经济案例', '民事案例','刑事案例'],
                kind:'',
                name:'',
                title:'',
                content:'',
                // 图片传服务器
                fileList: ''
            }
        },
        methods:{
            onConfirm(kind) {
                this.kind = kind;
                this.showPicker = false;
            },
            showPopup(){
              this.show = true
            },
            onClickLeft(){
                this.$router.push({path: 'caseManager'})
            },
            insertCase(){
                if (!this.kind){
                    this.$toast.fail('请选择案例类型!')
                }else if (!this.fileList){
                    this.$toast.fail('请粘贴一个图片地址！')
                }else if (!this.name){
                    this.$toast.fail('请输入案例名！')
                }else if (!this.title){
                    this.$toast.fail('请输入简介！')
                }else if (!this.content){
                    this.$toast.fail('请输入详细内容！')
                }else{
                    this.$axios.post('/case/insertCase',{
                        "lawCaseKind":this.kind,
                        "lawCaseImage":this.fileList,
                        "lawCaseName":this.name,
                        "lawCaseTitle":this.title,
                        "lawCaseContent":this.content,
                    },res =>{
                        this.$toast.success('添加成功！')
                        console.log(res)
                        this.$router.push('caseManager')
                    })
                }

            }
        },
        created() {
            this.caseList()
        }
    }
</script>

<style scoped>

</style>
